package com.youhong.teethcare;

import android.app.Activity;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.youhong.teethcare.adapter.PointAdapter;
import com.youhong.teethcare.services.Common;
import com.youhong.teethcare.utils.LanguageUtils;

import java.util.ArrayList;
import java.util.List;

public class PointsLevelActivity extends BaseActivity implements View.OnClickListener {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_points_level);
        getViews();
          setLevel(Common.userInfo.getScore());
      //  setLevel(560);
    }

    ImageView iv_level, iv_back;
    TextView tv_level, tv_points;
    TextView tv1, tv2, tv3, tv4, tv5, tv6, tv7, tv8, tv9;

    ImageView iv1, iv2, iv3, iv4, iv5, iv6, iv7, iv8, iv9;

    //int points = Common.userInfo.getScore();
    int points = Common.userInfo.getScore();

    private void getViews() {
        recyclerViewPoint = findViewById(R.id.RecyclerView_Point);
        iv_level = findViewById(R.id.PointLevel_iv_level);
        tv_level = findViewById(R.id.PointLevel_tv_levels);
        tv_points = findViewById(R.id.PointLevel_tv_Point);

        iv_back = findViewById(R.id.PointLevel_iv_back);
        iv_back.setOnClickListener(this);

    }

    private void setLevel(int score) {

        //显示分数和刷牙等级
        tv_points.setText(score + "");

        int level = 1;
        if (score < 500) {

            tv_level.setText(getResources().getString(R.string.strings139) + "1");
            iv_level.setImageDrawable(getResources().getDrawable(R.drawable.score_level1));
            level = 1;

        } else if (score < 2000) {
            level = 2;
            tv_level.setText(getResources().getString(R.string.strings139) + "2");
            iv_level.setImageDrawable(getResources().getDrawable(R.drawable.score_level2));


        } else if (score < 5000) {
            level = 3;
            tv_level.setText(getResources().getString(R.string.strings139) + "3");
            iv_level.setImageDrawable(getResources().getDrawable(R.drawable.score_level3));

        } else if (score < 10000) {
            level = 4;
            tv_level.setText(getResources().getString(R.string.strings139) + "4");
            iv_level.setImageDrawable(getResources().getDrawable(R.drawable.score_level4));


        }else{
            level = 5;
            tv_level.setText(getResources().getString(R.string.strings139) + "5");
            iv_level.setImageDrawable(getResources().getDrawable(R.drawable.score_level5));

        }
        initListView(level, score);
    }

    RecyclerView recyclerViewPoint;
    String[] scores = new String[]{"0", "500", "2000", "5000", "10000"};
    private static final String TAG = "PointsLevelActivity";

    void initListView(int level, int score) {
        Log.i(TAG, "initListView: " + level);
        GridLayoutManager gridLayoutManager = new GridLayoutManager(this, 2 );
        recyclerViewPoint.setLayoutManager(gridLayoutManager);
        List<String> list = new ArrayList<String>();
        for (int i = 0; i < scores.length; i++) {
            list.add(scores[i]);
        }

        PointAdapter pointAdapter = new PointAdapter(list, level, score);
        recyclerViewPoint.setAdapter(pointAdapter);

    }

    @Override
    public void onClick(View v) {

        if (v == iv_back) {

            this.finish();
        }

    }
}
